<script setup lang="ts">
import Taro, { showLoading, hideLoading, getCurrentInstance } from '@tarojs/taro';
import { useDayjs } from '@/hooks/common';
import { useNursePrivacy } from '@/service';
import { computed, ref } from 'vue';

const {
    router: {
        params: { id }
    }
}: any = getCurrentInstance();

const { $dayjs } = useDayjs();

const { queryById } = useNursePrivacy();

const data = ref({ title: '用户授权协议', createTime: '', updateTime: '', content: '' });

// definePageConfig({
//     navigationBarTitleText: data.value?.title
// });
Taro.setNavigationBarTitle({
    title: data.value?.title || ''
});
getData();

async function getData() {
    showLoading({ title: '正在请求数据...' });

    const { error, success } = await queryById(id);

    if (!error && success) data.value = success;

    hideLoading();
}

const format = computed(() => (date: string) => {
    return $dayjs(date).format('YYYY-MM-DD');
});
</script>
<template>
    <basic-layout>
        <!-- <custom-navbar :title="data?.title" showLeft /> -->
        <view class="w-375px flex-col-center mb-4">
            <view class="w-360px flex-col-center">
                <view class="my-2 font-bold text-lg">{{ data?.title }}</view>
                <view class="mb-2 text-blueGray">
                    {{ data?.createTime ? `生效时间:${format(data.createTime)}` : '' }}
                </view>
                <view class="mb-2 text-blueGray">
                    {{ data?.updateTime ? `更新时间:${format(data.updateTime)}` : '' }}
                </view>
                <view v-html="data?.content" class="content"></view>
            </view>
        </view>
    </basic-layout>
</template>
